package com.dark.index.web.controller;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.dark.common.repository.exception.DBException;
import com.dark.common.web.controller.BaseController;

/**
 * 用于测试相关的页面
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/admin/other")
public class OtherController extends BaseController {
	
	@RequestMapping(value="/aa1", method=RequestMethod.GET)
	public String aa1(Model model) {
		model.addAttribute("test", "你好") ;
		return viewName("aa1") ;
	}
	
	@RequestMapping(value="/aa2", method=RequestMethod.GET)
	public String aa2(Model model) {
		return viewName("aa2") ;
	}
	
	@RequestMapping(value="/aa3", method=RequestMethod.GET)
	public String aa3(Model model) {
		return viewName("aa3") ;
	}
	
	@RequestMapping(value="/aa4", method=RequestMethod.GET)
	public String aa4(Model model) {
		return viewName("aa4") ;
	}
	
	@RequestMapping(value="/aa5", method=RequestMethod.GET)
	public String aa5(Model model) {
		return viewName("aa5") ;
	}
	
	/*@ResponseStatus(value=HttpStatus.UNAUTHORIZED, reason="测试---")
	@ExceptionHandler({RuntimeException.class})
	public String handllerEx() {
		System.out.println("出错了.....");
		return "error/500" ;
	}*/
	
	@RequestMapping(value="/error1", method=RequestMethod.GET)
	public String error1(@RequestParam("i") int i) {
		if(i==13) { 
			throw new RuntimeException("错了...................") ;
		} 
		return viewName("error1") ;
	}
	
	/**
	 * 没有权限
	 * @return
	 * @throws UnauthorizedException
	 */
	@RequestMapping(value="/error2", method=RequestMethod.GET)
	public String error2() {
		throw new UnauthorizedException("Subject does not have permission");
	}
	
	@RequestMapping(value="/error3", method=RequestMethod.GET)
	public String error3() {
		throw new UnauthorizedException("Subject does not have role");
	}

	
	@RequestMapping(value="/error4", method=RequestMethod.GET)
	public String error4() {
		throw new UnauthorizedException("----------UnauthorizedException");
	}
	
	@RequestMapping(value="/error5", method=RequestMethod.GET)
	public String error5() {
		throw new DBException("DBUtil操作数据库异常") ;
	}
	
	@RequestMapping(value="/error6", method=RequestMethod.POST)
	public String error6() {
		throw new RuntimeException("Subject does not have permission");
	}
	
}
